import request from '@/utils/request'
import type { User, LoginForm, LoginResult, UserPageParams } from '@/types/user'
import type { PageResult } from '@/types/common'

// 登录
export const login = (data: LoginForm): Promise<LoginResult> => {
    return request.post('/auth/login', data)
}

// 登出
export const logout = (): Promise<void> => {
    return request.post('/auth/logout')
}

// 获取用户信息
export const getUserInfo = (): Promise<User> => {
    return request.get('/auth/userinfo')
}

// 获取用户列表
export const getUserList = (params: UserPageParams): Promise<PageResult<User>> => {
    return request.get('/users', { params })
}

// 创建用户
export const createUser = (data: Partial<User>): Promise<User> => {
    return request.post('/users', data)
}

// 更新用户
export const updateUser = (id: number, data: Partial<User>): Promise<User> => {
    return request.put(`/users/${id}`, data)
}

// 删除用户
export const deleteUser = (id: number): Promise<void> => {
    return request.delete(`/users/${id}`)
}

// 重置密码
export const resetPassword = (id: number, password: string): Promise<void> => {
    return request.post(`/users/${id}/reset-password`, { password })
} 